package com.jcrj.util;

import com.jcrj.entity.OInMail;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class MailHtmlUtil {
	private String getHtmlModle(OInMail mail) {
		StringBuffer buff = new StringBuffer();
		if (mail != null) {
			buff.append(mail.getTitle()).append("\n");
			buff.append("发件人：").append(mail.getSendName()).append("\n");
			buff.append("时间：").append(DateUtil.DateToFormat(mail.getCreateTime())).append("\n");
			buff.append("抄送人：").append(isEmpty(mail.getCNames())).append("\n");
			if ((mail.getContent() != null) && (!"".equals(mail.getContent()))) {
				String content = GetText.Html2Text(Base64.decode(mail.getContent()));
				buff.append(content);
			}
		}
		return buff.toString();
	}

	private static String isEmpty(Object obj) {
		if (obj == null) {
			return "";
		}
		return obj.toString();
	}

	public File getMailFile(OInMail mail) {
		File file = null;
		InputStream in = null;
		if (mail != null) {
			try {
				String path = SysConfig.getInstance().getProperty("mail.tempPath");
				FtpUploadUtil load = new FtpUploadUtil();
				String html = getHtmlModle(mail);
				String fileName = mail.getId() + ".doc";
				in = new ByteArrayInputStream(html.getBytes());
				load.uploadMailFile(in, path, fileName);
				file = new File(path + fileName);
			} catch (Exception e) {
				e.printStackTrace();

				if (in != null)
					try {
						in.close();
					} catch (IOException e1) {
						e1.printStackTrace();
					}
			} finally {
				if (in != null)
					try {
						in.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
			}
		}

		return file;
	}
}

/*
 * Location: /Volumes/work/oa/WEB-INF/classes/ Qualified Name:
 * com.jcrj.util.MailHtmlUtil JD-Core Version: 0.6.0
 */